if(MOD_ACT) {
  alert("Duplicated module MOD_ACT");
}

var MOD_ACT={
  act_action:'list',
  act_dn    :"",
  actype_sel:"",
  edit_act_id:0,
  callback:edit_allactions,
  printhook:printactions
};

var today= new Date(); 




MOD_ACT.def_replydate=function(actype,donedate) {
  var rdate;
  if(donedate) {
    rdate=str2Date(donedate);
  } else {
    rdate=new Date();
  }
  if(action_defaultRDATE(actype)) {
    rdate.setDate(rdate.getDate()+action_defaultRDATE(actype)); // html_selected("actype_sel",ACTSTYPES))); 
    return Date2str(rdate);
  }
  return "";
}

MOD_ACT.def_rwd=function(acttype) {
  return action_defaultRWD(acttype);
}

MOD_ACT.def_pax=function(acttype) {
  return action_defaultPAX(acttype);
}


MOD_ACT.def_limitdate=function(actype,dospri) {
  if(!dospri && GetDossier()) {
    dospri=GetDossierPri();
  } else {
    dospri="";
  }
  if(MOD_ACT.act_dn) {
    var ldate;
    // Use reference date is priority 
    if(action_defaultRefDate(actype)=="PR") {
      ldate=str2Date(dospri);
    } else {// Use reference date is last filing
      ldate=str2Date(GetClaimSetLastDate());
    }
    if(ldate && action_defaultLDATE(actype)) {
      ldate.setDate(ldate.getDate()+action_defaultLDATE(actype)); // html_selected("actype_sel",ACTSTYPES)
      return Date2str(ldate);
    }
  }
  return "";
}

//--------------------------------------------------------------------------------------
// New entry 
//--------------------------------------------------------------------------------------

MOD_ACT.onadd_action=function() {
  var dn= MOD_ACT.act_dn || document.getElementById("newdn").value;
  var an=document.getElementById("newan").value;
  var vers=document.getElementById("newver").value;
  var rwd=document.getElementById("newrwd").value;
  var trwd=""; //document.getElementById("newtrwd").value;
  var ldate=document.getElementById("newldate").value;
  var ddate=document.getElementById("newddate").value;
  var rdate=document.getElementById("newrdate").value;  
  var pax=document.getElementById("newpax").value;
  var typ=html_selected("actype_sel",ACTSTYPES);
  AddAction(dn,an,vers,typ,rwd,trwd,ldate,ddate,rdate,pax);
  if(action_isdead(typ)) {
    SetActionDead(dn,ddate);
  }
  MOD_ACT.callback();
}

MOD_ACT.onchdate=function(str) {
  if(str) {
    if(str.charAt(0)=="+") {
      var ndate=new Date();
      ndate.setDate(ndate.getDate()+(parseInt(str.substr(1))*30));
      return Date2str(ndate);
    } else {    
      return normalizeDate(str);
    }
  }
  return "";
}

MOD_ACT.onchldate=function(str) {
  document.getElementById("newldate").value=MOD_ACT.onchdate(str);  
}     	

MOD_ACT.onchrdate=function(str) {
  document.getElementById("newrdate").value=MOD_ACT.onchdate(str);  
}

MOD_ACT.onchrwd=function(str) {
  return;
}     	

MOD_ACT.onchangeacttype=function() {
  var actype=html_selected("actype_sel");
  //var dn=document.getElementById("newan").value;
  document.getElementById("newrwd").value=MOD_ACT.def_rwd(actype);
  document.getElementById("newpax").value=MOD_ACT.def_pax(actype);
  document.getElementById("newrdate").value=MOD_ACT.def_replydate(actype);
  if(MOD_ACT.act_dn) {
    document.getElementById("newldate").value=MOD_ACT.def_limitdate(actype);
  }
}

MOD_ACT.ondel_action=function(id) {
  if(confirm("Remove Action ?")) {
    RemoveAction(id);
    MOD_ACT.callback();
  }
}

//-----------------------------------------------------------------------------------------------
// Edit entry
//-----------------------------------------------------------------------------------------------

MOD_ACT.onchddate=function(str) {
  var donedate=MOD_ACT.onchdate(str);
  var actype=html_selected("actype_sel");
  document.getElementById("newddate").value=donedate;
  if(donedate) {
    document.getElementById("newrdate").value=MOD_ACT.def_replydate(actype,document.getElementById("newddate").value);
  }
}     	
  
MOD_ACT.onchedldate=function(str) {
  document.getElementById("edldate").value=MOD_ACT.onchdate(str);  
}

MOD_ACT.onchedrdate=function(str) {
  document.getElementById("edrdate").value=MOD_ACT.onchdate(str);  
}

MOD_ACT.onchedddate=function(str) {
  var actype=html_selected("actypeed_sel");
  document.getElementById("edddate").value=MOD_ACT.onchdate(str);  
  document.getElementById("edrdate").value=MOD_ACT.def_replydate(actype,document.getElementById("edddate").value);
}


MOD_ACT.onchedrwd=function(str) {
  return;
}

MOD_ACT.onchangeedacttype=function(){
  var actype=html_selected("actypeed_sel");
  document.getElementById("edrwd").value=MOD_ACT.def_rwd(actype);
  if(document.getElementById("edddate").value) {
    document.getElementById("edrdate").value=MOD_ACT.def_replydate(actype,document.getElementById("edddate").value);
  }
  document.getElementById("edldate").value=MOD_ACT.def_limitdate(actype);  
}


MOD_ACT.onedit_action=function(id) {
  MOD_ACT.edit_act_id=id;
  MOD_ACT.callback();
}

MOD_ACT.onupdate_action=function(id) {
  MOD_ACT.edit_act_id=0;
  var dn = MOD_ACT.act_dn || document.getElementById("eddn").value; 
  var typ=html_selected("actypeed_sel",ACTSTYPES);
  var ddate=document.getElementById("edddate").value;
  EditAction(id,
	     dn,
	     document.getElementById("edan").value,
	     document.getElementById("edver").value,
	     typ,
	     document.getElementById("edrwd").value,	     
	     "",
	     document.getElementById("edldate").value,
	     ddate,
	     document.getElementById("edrdate").value,
	     document.getElementById("edpax").value);
  if(action_isdead(typ)) {    
    SetActionDead(dn,ddate);
  }  
  MOD_ACT.callback();
}


//---------------------------------------------------------------------------------------

MOD_ACT.onclicksort=function(sf) {
  SetSortActionFunct(sf);
  MOD_ACT.callback();
}



MOD_ACT.onchprefmonth=function(m) {
  if(!m) {
    m=html_selectedidx("actmonth");
  }
  SetPrefMonth(m);
  MOD_ACT.callback();
}


MOD_ACT.viewactionentryheader=function(_opt) {
  var html="";
  if(!MOD_ACT.act_dn) {
    html+="<TH><button class='FULLSIZE' style='height:47' onclick='MOD_ACT.onclicksort(\"dn\");'>Dossier</button></TH>";
  }
  if(!_opt) {
    html+="<TH>Application</TH><TH>Version</TH>";
    html+="<TH><button class='FULLSIZE' style='height:47' onclick='MOD_ACT.onclicksort(\"type\");'>Type</button></TH>";
    html+="<TH><button class='FULLSIZE' onclick='MOD_ACT.onclicksort(\"ldate\");'>Limit<br>Date</button></TH>";
    html+="<TH><button class='FULLSIZE' onclick='MOD_ACT.onclicksort(\"ddate\");'>Done<br>Date</button></TH>"; 
    html+="<TH><button class='FULLSIZE' onclick='MOD_ACT.onclicksort(\"rdate\");'>Reply<br>Date</button></TH>";
    html+="<TH><button class='FULL' onclick='MOD_ACT.onclicksort(\"rwd\");'>Reward<br>CBF</button></TH>";
    html+="<TH><button class='FULL' onclick='MOD_ACT.onclicksort(\"pax\");'>Reward<br>PAX</button></TH>";
  } else {
    html+="<TH>Application</TH><TH>Version</TH><TH>Type</TH><TH>Limit</th><TH>Done</TH><TH>CBF</TH>";
  }
  return html;
}

MOD_ACT.on_setdoneaction=function(id){
  var donedate=Date2str(today);
  set_action_attr(id,"ddate",MOD_ACT.onchdate());
  if(donedate) {
    set_action_attr(id,"ddate",MOD_ACT.def_replydate(get_action_attr(id,"type"),donedate));
  }   
  MOD_ACT.edit_act_id=id;
  MOD_ACT.callback();
}


MOD_ACT.viewactionentry=function(act_iter,_opt) {
  if(MOD_ACT.edit_act_id == act_iter.getID()) {
    return MOD_ACT.editactionentry(act_iter);
  } else {
    var tml="<TR height=16>";
    if(!act_iter.is_final() && act_iter.is_last()) {
      if(!act_iter.getDDATE() && act_iter.getLDATE() && (str2Date(act_iter.getLDATE()) <= today)) {
	tml="<TR BGCOLOR=red>";
      }
      if(act_iter.getDDATE() && act_iter.getRDATE() && (str2Date(act_iter.getRDATE()) <= today)) {
	tml="<TR BGCOLOR=orange>";
      }
    }
    if(!MOD_ACT.act_dn) {
      tml+="<TD class='"+dossier_type(act_iter.getDN())+"'>";
      tml+=html_whatis("<A href='#' onclick='MOD_DOSSIER.onopendossier(\""+act_iter.getDN()+"\");'>"+act_iter.getDN()+"</A>",
		       "Click to Open")+"</TD>";
    }
    tml+="<TD>";
    tml+=html_whatis("<A href='#' onclick='show_dino(\""+act_iter.getAN()+"\")'>"+act_iter.getAN()+"</A>",
    //tml+=html_whatis("<A href='#' onclick='dino_inspect(\""+act_iter.getAN()+"\")'>"+act_iter.getAN()+"</A>",
		     "View in Dino")+"</TD>";
    tml+="<TD>"+act_iter.getVERS()+"</TD>";
    tml+="<TD>"+act_iter.getTYPE()+"</TD>";      
    tml+="<TD>"+act_iter.getLDATE()+"</TD>";
    if(act_iter.getDDATE()){
      tml+="<TD>"+act_iter.getDDATE()+"</TD>";
    } else {
      tml+="<TD><button onclick='MOD_ACT.on_setdoneaction("+act_iter.getID()+");'>Done</button></TD>";
    }
    if(!_opt) {
      tml+="<TD>"+act_iter.getRDATE()+"</TD>";
    }
    tml+="<TD>"+act_iter.getRWD()+"</TD>";
    tml+="<TD>"+act_iter.getPAX()+"</TD>";
    if(!_opt) {
      tml+="<TD><TABLE CLASS='ACTITAB'><TR><TD>";
      tml+="<button onclick='MOD_ACT.ondel_action("+act_iter.getID()+");'>"+html_img(minitrash_img)+"</button></TD>";
      tml+="<TD><button onclick='MOD_ACT.onedit_action("+act_iter.getID()+");'>"+html_img(miniedit_img)+"</button></TD>";
      tml+="</TR></TABLE></TD>";
    }
    tml+="</TR>";
  }
  return tml;
}  

MOD_ACT.editactionentry=function(act_iter) {
  var tml="<TR>";
  if(!MOD_ACT.act_dn) {
    tml+="<TD><INPUT TYPE=TEXT id=eddn  class='DOSNUM' VALUE='"+(act_iter.getDN() || "");
    tml+="' onchange='this.value=NormalizeDossierNumber(this.value);'></TD>";
  }
  tml+="<TD><INPUT TYPE=TEXT id=edan   class='APPNUM' VALUE='"+act_iter.getAN();
  tml+="' onchange='this.value=NormalizeDossierNumber(this.value);'></TD>";
  tml+="<TD><INPUT TYPE=TEXT id=edver   class='RALIGN' SIZE=3  VALUE='"+act_iter.getVERS()+"'></TD>";
  tml+="<TD>"+html_selection("actypeed_sel",ACTSTYPES,act_iter.getTYPE(),"MOD_ACT.onchangeedacttype()")+"</TD>";
  tml+="<TD><INPUT TYPE=TEXT id=edldate   class='DATE' onchange='MOD_ACT.onchedldate(this.value);' value='"+act_iter.getLDATE()+"'></TD>";
  tml+="<TD><INPUT TYPE=TEXT id=edddate  class='DATE' onchange='MOD_ACT.onchedddate(this.value);' value='"+act_iter.getDDATE()+"'</TD>";
  tml+="<TD><INPUT TYPE=TEXT id=edrdate  class='DATE' onchange='MOD_ACT.onchedrdate(this.value);' value='"+act_iter.getRDATE()+"'></TD>";
  tml+="<TD><INPUT TYPE=TEXT id=edrwd   class='RALIGN' SIZE=8 onchange='onchedrwd(this.value);'   value='"+act_iter.getRWD()+"'></TD>";
  tml+="<TD><INPUT TYPE=TEXT id=edpax   class='RALIGN' SIZE=8   value='"+act_iter.getPAX()+"'></TD>";
  tml+="<TD><TABLE CLASS='ACTITAB'><TR><TD>";
  tml+="<button onclick='MOD_ACT.edit_act_id=0;MOD_ACT.callback();' CLASS='ACTBUT'>"+html_img(cancel_img)+"</button></TD>";
  tml+="<TD><button onclick='MOD_ACT.onupdate_action("+act_iter.getID()+");'";
  tml+=">"+html_img(ok_img)+"</button></TD></TR></TABLE></TD>";
  tml+="</TR>";
  return tml;
}

MOD_ACT.addactionentry=function(act_dn) {
  var html="<TR>";
  if(!act_dn) {
    html+="<TD><INPUT TYPE=TEXT  id=newdn   class='DOSNUM' VALUE='"+(act_dn || "");
    html+="' onchange='this.value=NormalizeDossierNumber(this.value);'></TD>";
  }
  html+="<TD><INPUT TYPE=TEXT  id=newan  class='APPNUM'  VALUE='"+(act_dn ? GetClaimSetAppNum():"");
  html+="' onchange='this.value=NormalizeDossierNumber(this.value);'></TD>";
  html+="<TD><INPUT TYPE=TEXT  id=newver   class='RALIGN' SIZE=3   VALUE='"+(act_dn ? GetClaimSetVersion():"1")+"'></TD>";
  html+="<TD>"+html_selection("actype_sel",ACTSTYPES,"","MOD_ACT.onchangeacttype()")+"</TD>";

  html+="<TD><INPUT TYPE=TEXT  id=newldate  class='DATE' onchange='MOD_ACT.onchldate(this.value);' value='"+MOD_ACT.def_limitdate(ACTSTYPES[0])+"'></TD>";
  html+="<TD><INPUT TYPE=TEXT  id=newddate  class='DATE' onchange='MOD_ACT.onchddate(this.value);' value='"+Date2str()+"'</TD>";
  html+="<TD><INPUT TYPE=TEXT  id=newrdate  class='DATE'  onchange='MOD_ACT.onchrdate(this.value);' value='"+MOD_ACT.def_replydate(ACTSTYPES[0])+"'></TD>";
  html+="<TD><INPUT TYPE=TEXT  id=newrwd    class='RALIGN ' SIZE=8  onchange='MOD_ACT.onchrwd(this.value);' value='"+MOD_ACT.def_rwd(ACTSTYPES[0])+"'></TD>";

  html+="<TD><INPUT TYPE=TEXT  id=newpax    class='RALIGN ' SIZE=8  value='"+MOD_ACT.def_pax(ACTSTYPES[0])+"'></TD>";
  html+="<TD><BUTTON onclick='MOD_ACT.onadd_action();' CLASS='ACTBUT'>"+html_img(add_img)+"</BUTTON></TR>";    

  return html;
}

MOD_ACT.onchangeprodyear=function(year) {
  SetPrefYear(year);
  MOD_ACT._edit_allactions();
}

MOD_ACT.onchangeyeartgt=function(field,val) {
  SetYearTgt(GetPrefYear(),field,val);
  MOD_ACT._edit_allactions();
}

MOD_ACT.viewprodheader=function(year,month) {
  var html_header="";
  var tgtsr=GetYearTgt(year,"tgtsr");
  var tgtfa=GetYearTgt(year,"tgtfa");
  var tgtprod=GetYearTgt(year,"tgtprod");
  var daysdone=GetYearDone(year,"donedays");
  var tgtsrclass,tgtprodclass,tgtfaclass;

  if(tgtsr>0.0) {
    tgtsrclass="RALIGN RWTXT";
    if(tgtfa>0.0) {
      tgtfaclass="RALIGN RWTXT";
      tgtprodclass="RALIGN RESTXT";
      tgtprod=((0.6*tgtsr+0.4*tgtfa)/daysdone).toFixed(2);
    } else if(tgtprod>0.0) {
      tgtprodclass="RALIGN RWTXT";
      tgtfaclass="RALIGN RESTXT";
      tgtfa=(((daysdone*tgtprod)-0.6*tgtsr)/0.4).toFixed(0);
    }
  } else if(tgtfa>0.0 && tgtprod>0.0) {
    tgtsrclass="RALIGN RESTXT";
    tgtprodclass="RALIGN RWTXT";
    tgtfaclass="RALIGN RWTXT";    
    tgtsr=(((daysdone*tgtprod)-0.4*tgtfa)/0.6).toFixed(0);
  }
    
  html_header+="<TABLE><TR><TH>"; 
  html_header+="<fieldset><legend>Year</legend>";
  html_header+="<TABLE><TR><TD>";
  html_header+="<input type=button value='<' onclick='MOD_ACT.onchangeprodyear(GetPrefYear()-1)'><input type=text size=4 class='RALIGN' ";
  html_header+="onchange='MOD_ACT.onchangeprodyear(this.value)' value='"+year+"'><input type=button value='>' onclick='MOD_ACT.onchangeprodyear(GetPrefYear()-0+1)'>";
  html_header+="</TD></TR></TABLE>";
  html_header+="</fieldset></TH>";

  html_header+="<TH><fieldset><legend>Target</legend>";
  html_header+="<TABLE><TR>";
  html_header+="<TH>Searches <input type=text size=4 class='"+tgtsrclass+"' onchange='MOD_ACT.onchangeyeartgt(\"tgtsr\",this.value)'";
  html_header+=" value='"+tgtsr+"'></TH>";
  html_header+="<TH>Final<input type=text size=4 class='"+tgtfaclass+"' onchange='MOD_ACT.onchangeyeartgt(\"tgtfa\",this.value)'";
  html_header+=" value='"+tgtfa+"'></TH>";
  html_header+="<TH>Prod. <input type=text size=4 class='"+tgtprodclass+"' onchange='MOD_ACT.onchangeyeartgt(\"tgtprod\",this.value)'";
  html_header+=" value='"+tgtprod+"'></TH>";
  html_header+="</TR></TABLE>";
  html_header+="</fieldset></TH>";


  html_header+="<TH><fieldset><legend>To go</legend>";
  html_header+="<TABLE><TR>";
  html_header+="<TH>Searches <input type=text size=4 class='RALIGN' readonly ";
  html_header+=" value='"+(tgtsr-GetYearDone(year,"donesr"))+"'></TH>";
  html_header+="<TH>Final <input type=text size=4 class='RALIGN' readonly ";
  html_header+=" value='"+(tgtfa-GetYearDone(year,"donefa"))+"'></TH>";
  html_header+="</TR></TABLE>";
  html_header+="</fieldset></TH>";
 
  html_header+="<TH><fieldset><legend>% Done</legend>";
  html_header+="<TABLE><TR>";
  html_header+="<TH><input type=text size=4 class='RALIGN' readonly ";
  html_header+=" value='"+(100*(GetYearDone(year,"doneprod"))/tgtprod).toFixed(2)+"'></TH>";
  html_header+="</TR></TABLE>";
  html_header+="</fieldset></TH>";

  html_header+="</TR></TABLE>";
  html_header+="<BR>";
  return html_header;
}


MOD_ACT.onchprefyear=function(y) {
  SetPrefYear(y);MOD_ACT._edit_allactions();
}


MOD_ACT.viewactheader=function(year,month) {
  var html_header="<TABLE><TR><TH>";
  
  html_header+="<fieldset><legend>Year</legend>";
  html_header+="<input type=button value='<' onclick='MOD_ACT.onchprefyear(GetPrefYear()-1)'><input type=text size=4 class='RALIGN' ";
  html_header+="onchange='MOD_ACT.onchprefyear(this.value)' value='"+year+"'><input type=button value='>' onclick='MOD_ACT.onchprefyear(GetPrefYear()-0+1)'>";
  html_header+="</fieldset>";
  html_header+="</TH><TH>";
  html_header+="<fieldset><legend>Month</legend>";
  if(GetPrefMonth()==1) {
    html_header+="<input type=button value='<' disabled  onclick='MOD_ACT.onchprefmonth(GetPrefMonth()-1)'>";
  } else {
    html_header+="<input type=button value='<' onclick='MOD_ACT.onchprefmonth(GetPrefMonth()-1)'>";
  }
  html_header+=html_selection("actmonth",ALLMONTHS,ALLMONTHS[month],"MOD_ACT.onchprefmonth()");
  if(GetPrefMonth()==12) {
    html_header+="<input type=button value='>' disabled onclick='MOD_ACT.onchprefmonth(GetPrefMonth()-0+1)'>";
  } else {
    html_header+="<input type=button value='>' onclick='MOD_ACT.onchprefmonth(GetPrefMonth()-0+1)'>";
  }
  html_header+="</fieldset>";
  html_header+="</TH></TR></TABLE><BR>";
  
  return html_header;
}

MOD_ACT.listactionentries=function(actlist,_opt) {
  var html="";
  
  if(actlist) {
    html+="<TABLE border=1 CLASS='ACTITAB'><TR>"+MOD_ACT.viewactionentryheader(_opt)+"</TR>";  
    if(!_opt) {
      html+=MOD_ACT.addactionentry(MOD_ACT.act_dn);
    }
    // Show list of actions 
    act_iter= new actions_iterator(actlist);  
    while(!act_iter.end()) {
      html+=MOD_ACT.viewactionentry(act_iter,_opt);
      act_iter.next();
    }
    html+="</TABLE>";
  }
  return html;
}


MOD_ACT.viewprodyear=function(year) {
  var l_iter= new leave_iterator(year);
  var pfactor=parseFloat(GetPrefsProdFactor());
  var html_header="";
  var searches="";
  var final="";

  var rwd="";
  var months="";
  var prod="";
  var aprod="";
  var accnet=0;
  var accrwd=0.0;
  var accsearch=0;
  var accfinal=0;
  var tomonth=1+today.getMonth();
  //PAX
  var paxrwd="",paxprod="",paxaprod="";
  var lpax=0.0;
  var accpax=0.0;
  var pfinal="";
  var accpfinal=0;

  while(!l_iter.end()) {
    var act_iter= new actions_iterator(FindActionsDone(year,l_iter.getMonth()));  
    var lrwd=0.0;
    var lsearch=0;
    var lfinal=0;
    var lpax=0.0;
    var plfinal=0;
    
    while(!act_iter.end()) {
      if(act_iter.getDDATE()) {
	lrwd+=parseFloat(act_iter.getRWD());
	lpax+=parseFloat(act_iter.getPAX());
	if(action_isfinal(act_iter.getTYPE())) {
	  lfinal++;
	  plfinal+=act_iter.getPaxWeight();
	} else if(action_issearch(act_iter.getTYPE())) {
	  lsearch++;
	}
      }
      act_iter.next();
    }    

    accsearch+=lsearch;
    accfinal +=lfinal;
    accrwd   +=lrwd;
    accnet   +=l_iter.getNet();
    accpax   +=lpax;
    accpfinal+=plfinal;

    var bgcolor=(l_iter.getMonth() == tomonth) ? "BGCOLOR=orange" : "";
    
    months+="<TH "+(bgcolor || "bgcolor=lightblue")+">"+l_iter.getMonthName()+"</TH>";    
    searches+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      lsearch+"'></TD>";
    final+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      lfinal+"'></TD>";       	
    pfinal+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      plfinal+"'></TD>";       	
        
    paxrwd+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      lpax.toFixed(2)+"'></TD>";       	
    paxprod+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      (l_iter.getNet() ? (lpax/l_iter.getNet()) : 0.0).toFixed(2) +"'></TD>";
    paxaprod+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      (l_iter.getNet() ? (accpax/accnet) : 0.0).toFixed(2) +"'></TD>";

    rwd+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      lrwd.toFixed(2)+"'></TD>";       	
    prod+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      (l_iter.getNet() ? (pfactor*lrwd/l_iter.getNet()) : 0.0).toFixed(2) +"'></TD>";
    aprod+="<TD "+bgcolor+"><input type=text size=3 class='RALIGN GC'  value='"+
      (l_iter.getNet() ? (pfactor*accrwd/accnet) : 0.0).toFixed(2) +"'></TD>";


    l_iter.setField("doneprod",(l_iter.getNet() && lpax/l_iter.getNet()) || 0);
    l_iter.setField("doneprodacc",(accnet && accpax/accnet)||0);
    l_iter.setField("sr",lsearch);
    l_iter.setField("fa",plfinal);
    
    l_iter.next();
  }


  SetYearDone(year,"donesr"  ,accsearch);
  SetYearDone(year,"donefa"  ,accpfinal);
  SetYearDone(year,"donedays",accnet);
  SetYearDone(year,"doneprod",(accpax/accnet).toFixed(2));

  html_header+="<TABLE border=0><TR><TH></TH>"+months+"<TH>Total</TH></TR>";
  html_header+="<TR><TH align=left>Searches</TH>"+searches+"<TD align=right bgcolor=white>"+accsearch+"</TD></TR>";
  html_header+="<TR><TH align=left>Final</TH>"+final+"<TD align=right bgcolor=white>"+accfinal+"</TD></TR>";

  html_header+="<TR><TH>&nbsp</TH></TR>";

  html_header+="<TR><TH BGCOLOR=lightblue>Pax</TH></TR>"; //(accpax/accnet).toFixed(2)
  html_header+="<TR><TH align=left>Final</TH>"+pfinal+"<TD align=right bgcolor=white>"+accpfinal+"</TD></TR>";
  html_header+="<TR><TH align=left>Reward</TH>"+paxrwd+"<TD align=right bgcolor=white>"+(accpax.toFixed(2))+"</TD></TR>";
  html_header+="<TR><TH align=left>Productivity (t)</TH>"+paxprod+"<TD align=right bgcolor=white>"+GetYearDone(year,"doneprod")+"</TD></TR>";
  html_header+="<TR><TD></TD><TH colspan=13><HR></TH></TR>";
  html_header+="<TR><TH align=left>Productivity</TH>"+paxaprod+"<TD align=right bgcolor=white>"+GetYearDone(year,"doneprod")+"</TD></TR>";
  html_header+="<TR><TH>&nbsp</TH></TR>";
  html_header+="<TR><TH BGCOLOR=lightblue>ProProII</TH></TR>";
  html_header+="<TR><TH align=left>Reward</TH>"+rwd+"<TD align=right bgcolor=white>"+(accrwd.toFixed(2))+"</TD></TR>";
  html_header+="<TR><TH align=left>Productivity (t)</TH>"+prod+"<TD align=right bgcolor=white>"+(pfactor*accrwd/accnet).toFixed(2)+"</TD></TR>";
  html_header+="<TR ><TD></TD><TH colspan=13><HR></TH></TR>";
  html_header+="<TR><TH align=left>Productivity</TH>"+aprod+"<TD align=right bgcolor=white>"+(pfactor*accrwd/accnet).toFixed(2)+"</TD></TR>";
 
  
  html_header+="</TABLE><BR>";
  
 
  return html_header;
}

MOD_ACT.viewprodmonth=function(year,month) {
  var accrwd=0.0;
  var accsearch=0;
  var accfinal=0;
  var pfactor=parseFloat(GetPrefsProdFactor());  
  
  var l_iter= new leave_iterator(year);
  l_iter.seek(month);
  var html_header="";

  //alert("A"+year+" "+(l_iter.getMonth() || ""));
  var actlist=FindActionsDone(year,l_iter.getMonth());
  //alert(year+" "+(l_iter.getMonth() || ""));
  var act_iter= new actions_iterator(actlist);  
  while(!act_iter.end()) {
    if(act_iter.getDDATE()) {
      accrwd+=parseFloat(act_iter.getRWD());
      if(action_isfinal(act_iter.getTYPE())) {
	accfinal++;
      } else if(action_issearch(act_iter.getTYPE())) {
	accsearch++;
      }
    }
    act_iter.next();
  }    
  
  html_header+="<TABLE border=1><TR><TH>Searches</TH><TH>Final Actions</TH><TH>Reward</TH><TH>Productivity</TH></TR>";
  html_header+="<TD ALIGN=RIGHT><input type=text size=8 class='RALIGN GC'  value='"+accsearch+"'></TD>";
  html_header+="<TD ALIGN=RIGHT><input type=text size=8 class='RALIGN GC'  value='"+accfinal+"'></TD>";
  html_header+="<TD ALIGN=RIGHT><input type=text size=8 class='RALIGN GC'  value='"+accrwd.toFixed(2)+"'></TD>";
  html_header+="<TD ALIGN=RIGHT><input type=text size=8 class='RALIGN GC'  value='";
  html_header+=(pfactor*accrwd/l_iter.getNet()).toFixed(2)+"'></TD></TR>";
  html_header+="</TABLE><BR>";
  return html_header;
}

function build_graph(year) {
  var l_iter= new leave_iterator(year);
  var prods=new Array();
  var aprods=new Array();
  var sr=new Array();
  var fa= new Array();
  var months= new Array();
  var asr= new Array(); afa=new Array();
  var accsr=0,accfa=0;

  //GetYearTgt(year,"tgtprod");
  var str="";
  while(!l_iter.end()) {
    prods.push((10.0*l_iter.getField("doneprod")).toFixed(2));
    aprods.push((10.0*l_iter.getField("doneprodacc")).toFixed(2));
    sr.push(l_iter.getField("sr")|| 0);
    fa.push(l_iter.getField("fa")|| 0);
    accsr+=parseInt(l_iter.getField("sr"));
    accfa+=parseInt(l_iter.getField("fa"));
    asr.push(accsr || 0);
    afa.push(accfa || 0);
    months.push(l_iter.getMonthName());
    //str+=l_iter.getField("doneprod")+" ";
    l_iter.next();
  }
  asr.push(GetYearTgt(year,"tgtsr"));
  afa.push(GetYearTgt(year,"tgtfa"));
	   
  var t = new Graph(600,200);
  t.scale = 0.5;
  t.title = "Productivity (x10)";
  t.setXScaleValuesA(LMONTHS);
 
  t.addRowA(prods);
  t.addRowA(aprods);

  t.setLegend("Pax","Pax Avg");
 
  var f = new Graph(600,200);
  f.scale = 1;
  f.title = "Actions";
  f.setXScaleValuesA(LMONTHS);
  f.stacked=1;
  f.addRowA(sr);
  f.addRowA(fa);
  f.setLegend("SR","Final Actions");

  months.push("Tgt");
  var g = new Graph(600,200);
  g.scale = 10;
  g.title = "Actions/Target";
  g.setXScaleValuesA(months);
  g.stacked=1;
  g.addRowA(asr);
  g.addRowA(afa);

  g.setLegend("SR","Final Actions");
 

  
  return t.build()+" <BR> "+f.build()+" <BR> "+g.build();


  
}

MOD_ACT.PRODVIEWS=["Table","Graph"];
MOD_ACT.prodview=MOD_ACT.PRODVIEWS[0];


MOD_ACT._edit_allactions=function() {
  var html="";
  var year=GetPrefYear();
  var month=GetPrefMonth();

  var title="";

  ACT_MOD=MOD_ACT;
  CURRENTVIEW="actions";
  switch(MOD_ACT.act_action) {
  case "prod":
    title="<h2>Production </h2>";
    MOD_ACT.prodview=html_tabs_selected("prodview"  ,MOD_ACT.PRODVIEWS,MOD_ACT.prodview,"");
    //if(month==0) {
    var html2=MOD_ACT.viewprodyear(year); // refresh anual values 
    var tabhtml;
    switch(MOD_ACT.prodview) {
    case "Table":
      tabhtml=MOD_ACT.viewprodheader(year,0)+html2;
      break;
    case "Graph":
      tabhtml=MOD_ACT.viewprodheader(year,0)+"<BR>"+build_graph(year);
     break;
    }
    html+=html_tabs("prodview",MOD_ACT.PRODVIEWS,MOD_ACT.prodview,"MOD_ACT._edit_allactions()",tabhtml,MOD_ACT.PRODVIEWS);
    break;
  case "list":
    title="<h3>Action List </h3>"; 
    if(MOD_ACT.act_dn) {
      html=MOD_ACT.listactionentries(FindActions("dn",MOD_ACT.act_dn));
    } else {
      html=MOD_ACT.viewactheader(year,month)+MOD_ACT.listactionentries(FindActionsDone(year,month));
    }
    break;
  case "mydos":
    edit_myactions();
    return;
  case "todo":
    title="<h3>Todo List </h3>"; 
    html=MOD_ACT.listactionentries(FindActionsTodo());
    break;
  case "todie":
    title="<h3>Waiting action from applicant </h3>"; 
    html=MOD_ACT.listactionentries(FindActionsTodie());
    break;
  }

  html_display(title+html);
}


function printactions() {
  var html="";
  var year=GetPrefYear();
  var month=GetPrefMonth();
  var title="";
  switch(MOD_ACT.act_action) {
  case "prod":
    title="Production";
    if(month==0) {
      html=MOD_ACT.viewprodheader(year,month)+MOD_ACT.viewprodyear(year);
    } else {
      html=MOD_ACT.viewprodheader(year,month)+MOD_ACT.viewprodmonth(year,month);
    }
    break;
  case "list":
    if(MOD_ACT.act_dn) {
      title="Action List"; 
      html=MOD_ACT.listactionentries(FindActions("dn",MOD_ACT.act_dn),"prt");
    } else {
      html=MOD_ACT.viewprodheader(year,month,"prt")+MOD_ACT.listactionentries(FindActionsDone(year,month),"prt");
    }
    break;
  case "todo":
    title="Todo List"; 
    html=MOD_ACT.listactionentries(FindActionsTodo(),"prt");
    break;
  case "todie":
    title="Waiting action from applicant"; 
    html=MOD_ACT.listactionentries(FindActionsTodie(),"prt");
    break;
  }
  return "<h1>"+title+"</h1>"+html;  
}

function edit_myactions() {
  MOD_ACT.act_dn=GetDossierNumber() || "";
  MOD_ACT.act_action="mydos";
  MOD_ACT.callback=edit_myactions;

  ClaimToolEditSection("Edit Actions",
		       MOD_ACT.listactionentries(FindActions("dn",MOD_ACT.act_dn))
		       ,"edit_myactions()",
		       "","",
		       "do_dinonews();edit_myactions();");
  
}


function edit_allactions() {
  MOD_ACT.act_dn="";
  MOD_ACT.act_action="list";
  MOD_ACT.callback=edit_allactions;
  MOD_ACT._edit_allactions();
}

function edit_todoactions() {
  MOD_ACT.act_dn="";
  MOD_ACT.act_action="todo";
  SetSortActionFunct("ldate");
  MOD_ACT.callback=edit_todoactions;
  MOD_ACT._edit_allactions();
}

function edit_todieactions() {
  MOD_ACT.act_dn="";
  MOD_ACT.act_action="todie";
  SetSortActionFunct("rdate");
  MOD_ACT.callback=edit_todieactions;
  MOD_ACT._edit_allactions();
}

function edit_prodactions() {
  MOD_ACT.act_dn="";
  MOD_ACT.act_action="prod";
  SetSortActionFunct("ddate");
  MOD_ACT.callback=edit_prodactions;
  MOD_ACT._edit_allactions();
}

	 
